#include "EffectPool.h"
#include "EffectGenerator.h"
#include "Effect.h"

EffectPool::EffectPool(void)
{
}


EffectPool::~EffectPool(void)
{
	ClearPool();
}


Effect * EffectPool::GetEffect(int effectMask)
{
	if(effects.count(effectMask) == 0)
	{
		Effect * effect = EffectGenerator::GetPtr()->GenerateEffect(effectMask);
		effects[effectMask] = effect;
		effectMemoryHandler.push_back(effect);
		return effect;
	}
	else 
	{
		return effects[effectMask];
	}
}

void EffectPool::ClearPool()
{
	for(std::vector<Effect*>::iterator it = effectMemoryHandler.begin();it != effectMemoryHandler.end();++it)
	{
		if((*it) != nullptr)
		{
			delete (*it);
		}
	}

	effectMemoryHandler.clear();
}